/*
 * 文件名：BillRepairController.java
 * 版权：Copyright by www.tiansu-china.com/
 * 描述：
 * 修改人：congriran
 * 修改时间：2020年11月30日
 * 跟踪单号：
 * 修改单号：
 * 修改内容：
*/
 
package com.tiansu.reborn.wanda.modules.executor.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.tiansu.reborn.wanda.modules.executor.entity.FacadeResponse;
import com.tiansu.reborn.wanda.modules.executor.entity.vo.BillRepairCondVO;
import com.tiansu.reborn.wanda.modules.executor.service.BillRepairService;

import lombok.extern.slf4j.Slf4j;

@Controller
@Slf4j
public class BillRepairController
{
    @Autowired
    private BillRepairService billRepairService;

    @GetMapping("/bill_repair")
    public String index()
    {
        return "bill_repair";
    }

    @PostMapping("/downloadBill")
    public void downloadBill(HttpServletResponse response, @RequestBody BillRepairCondVO vo) throws IOException
    {
        billRepairService.downloadBill(response, vo);
    }

    @PostMapping("/uploadBill")
    @ResponseBody
    public FacadeResponse uploadBill(MultipartFile file)
    {
        FacadeResponse response = null;
        try
        {
            billRepairService.uploadBill(file);
            response = FacadeResponse.ok();
        }
        catch (Exception e)
        {
            response = FacadeResponse.error(e.getMessage());
            log.error("UploadBill error, error message is: " + e.getMessage());
        }
        return response;
    }
}
